package com.ybl.store.backend.controller.store;

import com.ybl.store.backend.dto.req.store.StoreSaveReqDTO;
import com.ybl.store.backend.dto.req.store.StoreUpdateReqDTO;
import com.ybl.store.backend.service.store.StoreService;
import com.ybl.store.common.entity.ListRespDTO;
import com.ybl.store.backend.dto.resp.store.StoreNameRespDTO;
import com.ybl.store.backend.dto.resp.store.StorePageRespDTO;
import com.ybl.store.common.convention.result.Result;
import com.ybl.store.common.convention.result.Results;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * 分店控制层
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/v1/backend/store")
public class StoreController {

    private final StoreService storeService;

    /**
     * 新增分店
     */
    @PostMapping
    public Result<Void> saveStore(@RequestBody StoreSaveReqDTO requestParam) {
        storeService.saveStore(requestParam);
        return Results.success();
    }

    /**
     * 根据 id 删除分店
     */
    @DeleteMapping
    public Result<Void> deleteStoreById(@RequestParam("id") Long id) {
        storeService.deleteStoreById(id);
        return Results.success();
    }

    /**
     * 修改分店
     */
    @PutMapping
    public Result<Void> updateStore(@RequestBody StoreUpdateReqDTO requestParam) {
        storeService.updateStore(requestParam);
        return Results.success();
    }

    /**
     * 禁用分店
     */
    @PutMapping("/ban")
    public Result<Void> banStore(@RequestParam Long id, @RequestParam Integer banFlag) {
        storeService.banStore(id, banFlag);
        return Results.success();
    }

    /**
     * 分组查询分店
     */
    @GetMapping("/page")
    public Result<StorePageRespDTO> pageStore(@RequestParam("pn") Integer pn, @RequestParam("ps") Integer ps) {
        return Results.success(storeService.pageStore(pn, ps));
    }

    /**
     * 查询分店名列表
     */
    @GetMapping("/list/name")
    public Result<ListRespDTO<StoreNameRespDTO>> listStoreName() {
        return Results.success(storeService.listStoreName());
    }
}
